Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hi.
How to add link to primary content in ObjectFormProcessor feedback message?
I want user to have a link to pdf file in inline message.
Thanks.
The following code provides the primary content download URL.
import wt.content.ApplicationData
import wt.content.ContentHelper
import wt.content.ContentRoleType
import wt.doc.WTDocument
import wt.fc.QueryResult
// Initialize from somewhere...
WTDocument doc;
doc = (WTDocument) ContentHelper.service.getContents(doc); QueryResult queryResult = ContentHelper.service.getContentsByRole(doc,ContentRoleType.PRIMARY);
URL url=null; if(queryResult.hasMoreElements()){ // There can be only one... url = ContentHelper.getDownloadURL(doc, (ApplicationData) queryResult.nextElement());
} // Test url, if it's null, no content.
// Otherwise, add it in the feedback message, within an <a href="url">downloadPrimary</a>
olivier fresse написал(а):
The following code provides the primary content download URL.
// Otherwise, add it in the feedback message, within an <a href="url">downloadPrimary</a>
Thanks, but the question is "how to add url to feedback message".
And the question is relevant for windchill version 11.
ok,
in your processor, you have a doOperation method. It returns a FormResult object. :
replace the "message" string with the html code to download the content, it should be ok.
import com.ptc.core.components.beans.ObjectBean
import com.ptc.core.components.forms.FormResult
import com.ptc.core.components.util.FeedbackMessage
import com.ptc.core.ui.resources.FeedbackType
import com.ptc.netmarkets.util.beans.NmCommandBean
FormResult doOperation(NmCommandBean nmCommandBean, List<ObjectBean> objectBeans) {
FormResult formResult = super.doOperation(nmCommandBean, objectBeans);
// do the job...
formResult.addFeedbackMessage(
new FeedbackMessage(
FeedbackType.SUCCESS,
nmCommandBean.getLocale(),
"Title",
null,
"message"));
return formResult;
}
It works in windchill 10, but it does not in windchill 11.
HTML tags do not work, they looked like text in message.
Hmm I see, same thing with workflow activities.
There is probably an html tag filtering to prevent xss attacks
Not sure it can be bypassed
Solution is simple.
All i need is provide my message(s) with flag MessagesCheckXSS = false (or MessagesCheckXSS array may be empty).
I'm using wnc 10 API but i need my code work in wnc 11.
So i implemented my own FeedbackMessage with overwritten method toJSONObject(). Example:
public class PTSFeedbackMessage extends FeedbackMessage {
/*size of this list equals number of messages*/
private List<Boolean> checkXSSList = new ArrayList<>();
/*constructors*/
@Override
public JSONObject toJSONObject() {
JSONObject resultObject = super.toJSONObject();
try {
if (!resultObject.has("MessagesCheckXSS")) {
resultObject.put("MessagesCheckXSS", new JSONArray());
}
JSONArray messagesCheckXSS = resultObject.getJSONArray("MessagesCheckXSS");
for(int i=0; i<checkXSSList.size(); i++) {
messagesCheckXSS.put(i, checkXSSList.get(i));
}
} catch (JSONException localJSONException) {
LOGGER.error("add MessagesCheckXSS error", localJSONException);
}
return resultObject;
}
}