Mitkees & Webcenter

Into the charm of Oracle Webcenter and ADF

Tag Archives: webcenter spaces

Update web.xml in webcenter portal


Sometimes you need to update the web.xml for webcenter portal if you want to disable compression or add servelets or change the session timeout.

As you know the webcenter potal (AKA Spaces before) is already deployed application .

In order to update the web.xml you need to create extension shared library and add web.xml to it with your updates. here are simple steps to do it:

  1. download webcenter extensions for jdevloper from here
  2. add these extensions to your jdevloper follow this blog
  3. create new application “webcenter portal server extension”
  4. you will find 2 projects “PortalExtension” & “PortalSharedLibrary”
  5. expand PortalSharedLibrary and find the web.xml under WEB-INF
  6. update web.xml as you want
  7. right click on project > project properties > deployment> edit
  8. under web files mark the web.xml to be included in the deployment.
  9. ok then ok
  10. locate the MANIFEST.MF under the project
  11. change the version Implementation-Version & Specification-Version
  12. save
  13. deploy to the server
  14. restart the managed server

Change the webcenter portal language selector task flow to be links instead of popup


The current portal language selector is a popup that shows the available languages to select from .

what if you need to create links or drop down with 2 languages only?!

you can use this code and pass the locale to the parameters

 <af:commandLink styleClass="topNavLinks frlink" rendered="#{facesContext.externalContext.requestLocale eq 'en'}" partialSubmit="false" id="frlink" actionListener="#{o_w_wa_chooseLanguage.changeLanguage}" text="French">
<f:attribute name="wcLangId" value="fr"/>
</af:commandLink>
<af:commandLink styleClass="topNavLinks enlink" rendered="#{facesContext.externalContext.requestLocale eq 'fr'}" partialSubmit="false" id="enlink" actionListener="#{o_w_wa_chooseLanguage.changeLanguage}" text="English">
<f:attribute name="wcLangId" value="en"/>
</af:commandLink>

Webcenter portal & ADF Responsive


After implementing ADF & portal responsive I have concluded many hints to follow while implementing
The main problem of the responsive it that adf components render as table
1- Limit the use of the components that render tables in the html dom and use html code if needed in verbatim tag
2- Limit the use of layout component that has tables or horizontal layout as it render in tables
Hints
• Preferably use bootstrap templates.
• Create templates with panelgrouplayout vertical & default and create a custom style class to make it to horizontal example ;

.VTOH{
width:100%;
float:left;
margin:0;
padding:0;
} 

• In portal use panel customizable under each other don’t implement it horizontal preferably add it in panelgrouplautout and use the above class & css to draw your page.
• Do the responsive in one CSS file and import it in your template and use media queries inside it.
• All width should in percentage. You may use with for small components on the page but that would be difficult in responsive.
• If you are obliged or have to use component that have fixed width use java script to change the width in responsive.

Adding the new custom attribute to Webcenter spaces User Profile?:-


First add new custom attribute to LDAP:-

1         Click Run from Start menu and type ‘mmc’.

2         Click Fileà Add à Add to Active Directory Schema

3         Right Click on Attributes à New à Attribute.

4         Then add this attribute to the “User” Class under Classes.

5         Now, you can see the new attribute in the ADSI for each user object.

Image

  • We can do that by the “Custom Oracle Webcenter Spaces Application – Profile Attributes Project”.
  • There are two java classes under this project:-
  1. CustomProfileImpl.java: This class is used to override the value of an existing attribute or make it come from other data source: To override the existed attribute just add the code to this class as per the following

–          We can use JSFUtils.java class to make personalized view for each user (each user can see his image from a specific data source).

  1. The Second Class (ExtendedProfileAttributes.java): This class is used to add a new custom attribute to user profile

–          First, We add a new attribute to the class and generate its assessors (getter and setter)

–          Then Add your code in the getter Property to get the value of the attribute in the read-only mode (while you are viewing your profile as a spaces user) and add your code in the Setter Property to set the value the user enters in the edit mode of the task flow to a specific data source (Active Directory).

–          Add JSFUtils.java to the ProfileAttributes project in the same package as ExtendProfileAttributes.java class (custom.webcenter.spaces) to be able to get or set values to expression language used by webcenter.

–          Add  . properties file to the ProfileAttributes project and add the values of the data source you are connecting to as per the following example:-

#This File contain the LDAP Configurations

INITIAL_CONTEXT_FACTORY = com.sun.jndi.ldap.LdapCtxFactory

SECURITY_AUTHENTICATION = simple

SECURITY_PRINCIPAL= cn=orcladmin

# SECURITY_PRINCIPAL= BPEL_TEST@sfdproject.com

SECURITY_CREDENTIALS = welcome1

PROVIDER_URL = ldap://myldap:port

TokenGroups = java.naming.ldap.attributes.binary

UserBase = dc=sfdproject, dc=com

username = sAMAccountName

testAttribute= testAttribute

–          In the getter property (which will be called in the view mode) write the following code:-

try {

String spaceUser =(String)JSFUtils.resolveExpression(&amp;quot;#{securityContext.userName}&amp;quot;);

System.out.println(&amp;quot;This is the Extend constructor: &amp;quot;+spaceUser);

if(spaceUser !=null &amp;amp;amp;&amp;amp;amp; spaceUser != &amp;quot;&amp;quot; &amp;amp;amp;&amp;amp;amp; !spaceUser.toLowerCase().equals(&amp;quot;anonymous&amp;quot;))
{connectLDAP(spaceUser);}

}

catch (Exception e) {

e.printStackTrace();

}

public void connectLDAP(String name) throws NamingException {

bundle = ResourceBundle.getBundle(Path of your property file in the ProfileAttributes project);

Hashtable&amp;amp;lt;String, String&amp;amp;gt; env = new Hashtable&amp;amp;lt;String, String&amp;amp;gt;();

env.put(Context.INITIAL_CONTEXT_FACTORY,

bundle.getString(&amp;quot;INITIAL_CONTEXT_FACTORY&amp;quot;));

env.put(Context.PROVIDER_URL, bundle.getString(&amp;quot;PROVIDER_URL&amp;quot;));

env.put(Context.SECURITY_PRINCIPAL,
bundle.getString(&amp;quot;SECURITY_PRINCIPAL&amp;quot;));

env.put(Context.SECURITY_CREDENTIALS,

bundle.getString(&amp;quot;SECURITY_CREDENTIALS&amp;quot;));

LdapContext ctx = (LdapContext)new InitialLdapContext(env, null);

DirContext dtx = (DirContext)ctx.lookup(bundle.getString(&amp;quot;UserBase&amp;quot;)); // UserBase is a key in the property file

SearchControls ctls = new SearchControls();

ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

String filter = &amp;quot;(sAMAccountName=&amp;quot; + name + &amp;quot;)&amp;quot;;

NamingEnumeration e = dtx.search(&amp;quot;&amp;quot;, filter, ctls);

if (e.hasMore()) {
SearchResult entry = (SearchResult)e.next();

answer = entry.getAttributes();

//ctx.getAttributes(&amp;quot;cn=&amp;quot; + name + &amp;quot;,&amp;quot; + bundle.getString(&amp;quot;UserBase&amp;quot;)); //ou=OrgUnit1,

System.out.println(&amp;quot;answer.get(\&amp;quot;manager\&amp;quot;): &amp;quot; + answer.get(&amp;quot;manager&amp;quot;));

this.testAttribute = answer.get(&amp;quot;testAttribute&amp;quot;).toString();

ctx.close();

}

}

–          In the setter property (which will be called in the edit mode) write the following code:-

try {

String spaceUser = (String)JSFUtils.resolveExpression(&amp;quot;#{securityContext.userName}&amp;quot;);
System.out.println(&amp;quot;This is the Extend constructor: &amp;quot;+spaceUser);

if(spaceUser !=null &amp;amp;&amp;amp;; spaceUser != &amp;quot;&amp;quot; &amp;amp;&amp;amp; !spaceUser.toLowerCase().equals(&amp;quot;anonymous&amp;quot;) )

{

System.out.println(&amp;quot;The new value entered by user: &amp;quot;+ testAttribute);

connectLDAP1(spaceUser,testAttribute);

}

}

catch(Exception e) {

e.printStackTrace();

}

public void connectLDAP1(String name,String newValue) throws NamingException {

bundle = ResourceBundle.getBundle(&amp;quot;invokeprops//LDAP&amp;quot;);

System.out.println(&amp;quot;The new value entered by user: &amp;quot;+ newValue);

Hashtable&amp;lt;String, String&amp;gt; env = new Hashtable&amp;lt;String, String&amp;gt;();

env.put(Context.INITIAL_CONTEXT_FACTORY,

bundle.getString(&amp;quot;INITIAL_CONTEXT_FACTORY&amp;quot;));

env.put(Context.PROVIDER_URL, bundle.getString(&amp;quot;PROVIDER_URL&amp;quot;));

env.put(Context.SECURITY_PRINCIPAL,bundle.getString(&amp;quot;SECURITY_PRINCIPAL&amp;quot;));

env.put(Context.SECURITY_CREDENTIALS,

bundle.getString(&amp;quot;SECURITY_CREDENTIALS&amp;quot;));

LdapContext ctx = (LdapContext)new InitialLdapContext(env, null);

DirContext dtx = (DirContext)ctx.lookup(bundle.getString(&amp;quot;UserBase&amp;quot;));

SearchControls ctls = new SearchControls();

ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

String filter = &amp;quot;(sAMAccountName=&amp;quot; + name + &amp;quot;)&amp;quot;;

NamingEnumeration e = dtx.search(&amp;quot;&amp;quot;, filter, ctls);

if (e.hasMore()) {

SearchResult entry = (SearchResult)e.next();

answer = entry.getAttributes();

//ctx.getAttributes(&amp;quot;cn=&amp;quot; + name + &amp;quot;,&amp;quot; + bundle.getString(&amp;quot;UserBase&amp;quot;)); //ou=OrgUnit1,

System.out.println(&amp;quot;answer.get(\&amp;quot;manager\&amp;quot;): &amp;quot; + answer.get(&amp;quot;manager&amp;quot;));

//  answer.put(&amp;quot;testAttribute&amp;quot;, newValue);

ModificationItem[] mods = new ModificationItem[1];

mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,

new BasicAttribute(&amp;quot;testAttribute&amp;quot;, newValue));

dtx.modifyAttributes(&amp;quot;cn=legalm,cn=users&amp;quot;, mods);

ctx.close();

}

}
  • Then, deploy WebcenterSpacesSharedLibExtension project using the Ant Apache after adding the jar of the ProfileAttributes Project to the War of the WebcenterSpacesSharedLibExtension project as per the next image

Image

  • Then, Log in to the spaces with administrator user and navigate to the Resources of the group space you need to add the new attribute to, then choose the resource catalog you need and AddàNew Component and write this code down (in this example the added attribute called testAttribute).

Image<af:panelLabelAndMessage xmlns:af=”http://xmlns.oracle.com/adf/faces/rich&#8221; label=”Project ” labelStyle=”font-weight:bold;” id=”#”><af:inputText value=”#{wcProfileCustomAttribute[(pageFlowScope.userId == null ? securityContext.userName : pageFlowScope.userId)].testAttribute}” simple=”true” columns=”40″ maximumLength=”50″ shortDesc=”Enter project details” id=”#”/></af:panelLabelAndMessage>

Image
  • We may need to add two components (one for read only mode with <af:outputText> and the other for the edit mode as per the above code).
  • Navigate to the User Profile page (My Profile) from the system pages of the personal space
  • In the About tab you have many task flow, you choose the task flow you need and add your component to it (you must view the source to add your component to a specified task flow) Image
  • Click on the task flow you need to add your component to and a message displayed says that all instances of the task flow will be affected (click Edit)    Image
  • After Clicking on edit, the source of the task flow appeared , choose the place you need to add the component to and click on Add content   Image
  • Choose your component and click Save and Close.

ENJOY THE MAGIC

Webcenter Document Service: Remove “IDC Profile:” prefix in upload page


First let me show you the issue , it appears when you click on upload  button in Webcenter Document Service

We are going remove that prefix as it is not user friendly,So we have to customize the Document service.

  1. To enable taskflow Customization use this document http://www.oracle.com/technetwork/middleware/webcenter/owcs-ps1-custom-taskflow-wp-129410.pdf
  2. Create a new webcenter customization project
  3. show libraries
  4. navigate to the following package
  5. open the two files upload.jsff and profileUpload.jsff and add a client listener as the next 2 snapshots

    the update should appear in xml files like that
  6. Save All
  7. Deploy application to mar
  8. connect to WLST and Use the following script to deploy the mar to webcenter metadataimportMetadata(application=’webcenter’, server=’WC_Spaces’, fromLocation=’C:\metadata.mar’)

now it should be removed.

%d bloggers like this: