1 5 package org.exoplatform.portlets.user.renderer.html; 6 7 import java.io.IOException ; 8 import java.util.Iterator ; 9 import java.util.ResourceBundle ; 10 import javax.faces.component.UIComponent; 11 import javax.faces.context.FacesContext; 12 import javax.faces.context.ResponseWriter; 13 import org.exoplatform.faces.core.component.model.Parameter; 14 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer; 15 import org.exoplatform.portlets.user.component.UIUserInfo; 16 import org.exoplatform.services.organization.Membership; 17 21 public class UserInfoRenderer extends HtmlBasicRenderer { 22 private static Parameter DELETE_MEMBERSHIP = new Parameter(ACTION , "deleteMembership") ; 23 private static Parameter[] backParams = {new Parameter(ACTION , "back")} ; 24 25 final public void encodeBegin( FacesContext context, UIComponent component ) throws IOException { 26 ResourceBundle res = getApplicationResourceBundle(context.getExternalContext()) ; 27 ResponseWriter w = context.getResponseWriter() ; 28 29 UIUserInfo uiUserInfo = (UIUserInfo) component ; 30 w.write("<table class='UIUserInfo'>"); 31 w. write("<tr>"); 32 w. write("<td class='form'>"); 33 uiUserInfo.getUIAccountForm().encodeChildren(context) ; 34 w. write("</td>"); 35 w. write("<td class='user-roles'>"); 36 addUserRoleInfo(context, res, uiUserInfo) ; 37 w. write("</td>"); 38 w. write("</tr>"); 39 w. write("<tr>"); 40 w. write("<td colspan='2' class='footer'>"); 41 linkRenderer_.render(w,uiUserInfo, res.getString("UIUserInfo.button.back"), backParams) ; 42 w. write("</td>"); 43 w. write("</tr>"); 44 w.write("</table>"); 45 } 46 47 private void addUserRoleInfo(FacesContext context, 48 ResourceBundle res, UIUserInfo uiUserInfo) throws IOException { 49 ResponseWriter w = context.getResponseWriter() ; 50 Iterator memberships = uiUserInfo.getMemberships().iterator() ; 51 Parameter membershipIdParam = new Parameter("membershipId", "") ; 52 Parameter[] deleteMembershipParams = { DELETE_MEMBERSHIP , membershipIdParam } ; 53 w.write("<table>"); 54 w. write("<tr>"); 55 w. write("<th>"); 56 w. write(res.getString("UIUserInfo.header.membership")); 57 w. write("</th>"); 58 w. write("<th>"); 59 w. write(res.getString("UIUserInfo.header.membership-type")); 60 w. write("</th>"); 61 w. write("<th>"); 62 w. write(res.getString("UIUserInfo.header.group-id")); 63 w. write("</th>"); 64 w. write("<th>-</th>"); 65 w. write("</tr>") ; 66 int i = 0; 67 while (memberships.hasNext()) { 68 Membership membership = (Membership) memberships.next(); 69 String clazz = "odd"; 70 if (i % 2 == 0) clazz = "even"; 71 w.write("<tr class='" + clazz + "'>") ; 72 w. write("<td>") ; w.write("Membership") ; w.write("</td>") ; 73 w. write("</td>"); w.write("<td>"); w.write(membership.getMembershipType()); w.write("</td>") ; 74 w. write("<td>") ; w.write(membership.getGroupId()) ; w.write("</td>") ; 75 if(uiUserInfo.hasAdminRole()) { 76 w.write("<td>"); 77 membershipIdParam.setValue(membership.getId()) ; 78 linkRenderer_.render(w, uiUserInfo, res.getString("UIUserInfo.button.delete"), deleteMembershipParams) ; 79 w.write("</td>"); 80 } else { 81 w.write("<td> - </td>"); 82 } 83 w.write("</tr>") ; 84 i++; 85 } 86 w. write("</tr>"); 87 w. write("<tr>"); 88 w. write("<td class='form' colspan='4'>"); 89 uiUserInfo.getUIMembershipForm().encodeChildren(context) ; 90 w. write("</td>"); 91 w. write("</tr>"); 92 w.write("</table>"); 93 } 94 } | Popular Tags |