if (!SessionErrors.isEmpty(req)) {
return mapping.findForward("portlet.portlet_name.error");
}
Tuesday, September 7, 2010
Liferay Struts Portlet: Usage of SessionErrors class...
Wednesday, June 9, 2010
Liefray: Using JSONObject for Ajax in Plugin Portlet...
$.ajax({
type: 'POST',
url: getUrl(),
data: {},
success: function(returnData) {
$('#someElementId').html(returnData);
}
}); protected void getSomeDataAsJson(ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
String myParam = ParamUtil.getString(request, "myParam","");
// Some service call using params from request...
Obj obj = getDataFromSomeService(myParam);
JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
// obj can be anything... Integer,Boolean,String or some custom POJO...
jsonObj.put("testData", obj);
OutputStream os = response.getPortletOutputStream();
try {
os.write(jsonObj.toString().getBytes());
}
finally {
os.close();
}
}
@Override
public void serveResource(ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
String cmd = ParamUtil.getString(request,Constants.CMD);
if ("getSomeDataAsJson".equals(cmd)) {
getSomeDataAsJson(request, response);
}
} $("input:button[@name='<portlet:namespace />SomeThing']").click (function() {
$('#<portlet:namespace />myDiv').text("");
//URL which goes to your portlet...
var url = "<portlet:resourceURL><portlet:param name='<%=Constants.CMD %>' value='getSomeDataAsJson' /></portlet:resourceURL>";
//Append your hidden input fields in the resourceURL...
url +="&"+$('input:hidden').serialize();
$.ajax({
url: url,
data: {},
dataType: 'json',
success: function(message) {
$('#<portlet:namespace />myDiv').text(message.testData);
}
}
);
}); Posted by Parth Barot at 3:32 PM 2 comments
Labels: API, Articles, Frameworks, Html, javascript, JQuery, Liferay, Open Source, Programming, struts, Tips, web
Thursday, May 1, 2008
Using Struts tags - <logic:iterate>,<logic:equal>,<bean:write>
I was wondering what should i write about now.And suddenly i got this to do.
I have a small change in the jsp which is made using struts framework.In struts, there are many tags which are easy to use and generate output fast.easy to write.
In struts, we have ActionServlet,Action classes and ActionForms.
ActionServlet will transfer the request to ActionServlet with ActionForms containing all the HTML form data.so you can access any data of the of ActionForm from Servlet request.
See the below code.then we will talk regarding it.<select name="sel1" id="selTestStruts" style="width:90px;">
<option value="0" selected="selected">Please Select
<logic:iterate id="myBean" name="someForm" property="someFormProp1">
<logic:equal value="test" property="someStrPropOfMyBean" name="myBean">
<option value='<bean:write name="myBean" property="someStrPropOfMyBean"/>'><bean:write name="myBean" property="someNamePropOfMyBean"/></option>
</logic:equal>
</logic:iterate>
</select>
here we are trying to fill HTML select box using struts' <logic:iterate>, <logic:equal><bean:write> tags.<logic:iterate> will iterate on 'someFormProp1' of 'someForm' which is in the http request.it will make 'myBean' from property 'someFormProp1' which is a List of some data.
You can simply write any property from that 'myBean' we made above.But i also shown here how you can put logic to seperate things on some property value so you don't need to put logic in the SP or generate another property for it.<logic:equal> checks the value of property named 'someStrPropOfMyBean' with the string given in 'value="test"' attribute (means with 'test' here). If the value matches then only it will make new <option> for <select> box.
same thing you can do with not including some specific value match using <logic:notEqual><bean:write> tag will simply write property 'someStrPropOfMyBean' of 'myBean' which is a object of some Value Object class from the List property 'someFormProp1' of 'someForm'.
Though this is very simple thing but i write because may be this can be helpful to some newbies.
Posted by Parth Barot at 7:07 PM 0 comments
Labels: Articles, Development, Frameworks, Html, Open Source, Programming, struts, Tips, Tutorials, web