Forums de discussion

Icefaces, ServiceContext and addUser

Benjamin Becker, modifié il y a 13 années.

Icefaces, ServiceContext and addUser

New Member Publications: 22 Date d'inscription: 11/03/10 Publications récentes
Hi Liferay developers,

I'am writing a JSF(Icefaces) based login portlet, where you also can register a new user. I thougt it will be easy, but now I'am have a problem to add a new user. I use the following methode to create a new user:

UserServiceUtil.addUser(companyId, autoPassword, password, passwordCheck, autoScreenName, username, 
eMailAddress, openId, locale, firstName, "", lastName, 0, 0, male, birthdayMonth, birthdayDay, 
birthdayYear, "", groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);


The probelm is the last parameter of this methode, the parameter called serviceContext. I thought it will be possibile to get serviceContext by the following code snippet, but I can't get an ActionRequest, only a RenderRequest.

serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);


Can anyone help me to get the ActionRequest or does anyone have a workaround for that problem. Thanks a lot.

Regard Benjamin
Benjamin Becker, modifié il y a 13 années.

RE: Icefaces, ServiceContext and addUser

New Member Publications: 22 Date d'inscription: 11/03/10 Publications récentes
I solved this problem by creating a new service context. I used the following line:
ServiceContext serviceContext = new ServiceContext();

instead of:
serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

Regards Benjamin
thumbnail
Neil Griffin, modifié il y a 13 années.

RE: Icefaces, ServiceContext and addUser

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
The PortletFaces-Tools project has a FacesContext decorator called PortletFacesContext that has a getServiceContext() method. It pre-populates the ServiceContext instance as much as possible, in a non-JSP environment like Facelets. After that, it's up to you to call the setter methods to set Tags, Categories, etc.. if necessary. Normally it's not.

Also, you'll run into a problem with ICEfaces 1.8 in which Liferay services like UserServiceUtil.addUser(...) might fail because ICEfaces 1.x Ajax requests don't go through the Portlet RESOURCE_PHASE. The PortletFaces-Tools project has a PhaseListener built into it that fixes this problem for you. Note that the PortletFaces-Bridge for ICEfaces 2.0 will indeed send Ajax requests via the portlet RESOURCE_PHASE and this won't be a problem.