How to make attachments mandatory?

Scenario : A Page consists of an item with style attachmentLink which provides standard functionality for attachments. And during page submit, you need to check whether any attachments exist or not and throw an error if there is no attachment.

Solution : 

OAMessageAttachmentLinkBean oamessageattachmentlinkbean = (OAMessageAttachmentLinkBean)oawebbean.findChildRecursive(“AttachmentLink”);

 String val = (String)oamessageattachmentlinkbean.getAttributeValue(oapagecontext.getRenderingContext(),TEXT_ATTR);

if(“None”.equals(val)) {     throw new OAException(“Attachments are mandatory”,OAException.ERROR);  }

Advertisements
This entry was posted in OAF. Bookmark the permalink.

6 Responses to How to make attachments mandatory?

  1. Vaddi Rakesh says:

    Many thanks for information.
    However the getAttributeValue parameters are not clearly printed on this webpage. Can you please let me know, the exact parameters.

    Rgds

    Vaddi Rakesh

    • Sowjanya Bhupathiraju says:

      Hi Rakesh,

      getAttributeValue in this code is having two parameters.
      1. oapagecontext.getRenderingContext() : getRenderingContext gives the rendering context of your page.

      2. TEXT_ATTR : this is a predefined constant.

      Let me know if you need more info.

      Thanks,
      Sowjanya

  2. ranita says:

    Hi,
    I have the exact same requirement.
    but this is not working for me, For me String val is always ‘null’

    please tell me with which CO u r attaching this code?

    I am not able to throw the error after clicking submit button

    • Sowjanya Bhupathiraju says:

      Hi Ranita,

      Sorry for the late reply. I wrote the code in the base CO i.e the CO in which the message attachment link bean is present.

      Thanks,
      Sowjanya.

  3. atif Dar says:

    When I try to compile attached file following errors comes:
    OAMessageAttachmentLinkBean cannot be resolved to a type
    OAMessageAttachmentLinkBean cannot be resolved to a type
    oawebbean cannot be resolved
    oapagecontext cannot be resolved

  4. Ahmed Galal says:

    Thank you very much for your code, I didn’t find it anywhere except here.
    It works very fine with me except that you have to consider space character after “None” in the code
    i.e.

    (“None “.equals(val)) //—> “None”+space char.equal(val)

    keep up Good work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s