Dynamically add Children Link Element

Hi,
I'm trying to dynamically add a children element, a link, but the action binding refuses to work ...
I've created a custom jsf component, that does nothing at all.
For example, one would use it like:
<my:nothing></my:nothing>So my UI class would have the following methods:
public void encodeBegin(FacesContext context) throws IOException {
public void encodeEnd(FacesContext context) throws IOException {
}The tld file is created, the tag class is working. All the component is working properly.
Now I want to add a link as a child component, but I wat to do it programatically, so I changed the encodeBegin method of my custom ui class:
import javax.faces.el.ValueBinding;
import com.sun.faces.util.Util;
import javax.faces.el.MethodBinding;
import javax.faces.component.UICommand;
import javax.faces.component.html.HtmlCommandLink;
import com.sun.faces.taglib.html_basic.CommandLinkTag;
public void encodeBegin(FacesContext context) throws IOException {
          String myLinkId = "idMyLink";
          String myLinkValue = "myLink:Value";
          String myLinkStyle = "color:green;";
          String myLinkAction = "backup";
          HtmlCommandLink myLink = new HtmlCommandLink();
          myLink.setParent(this);
          myLink.setId( myLinkId );
          if (CommandLinkTag.isValueReference( myLinkValue )) {
               ValueBinding vb = Util.getValueBinding( myLinkValue );
               myLink.setValueBinding("value", vb);
          } else {
               myLink.setValue( myLinkValue );
          if (CommandLinkTag.isValueReference( myLinkStyle )) {
               ValueBinding vb = Util.getValueBinding( myLinkStyle );
               myLink.setValueBinding("style", vb);
          } else {
               myLink.setStyle( myLinkStyle );
          if(myLinkAction!=null) {
               if (CommandLinkTag.isValueReference( myLinkAction )) {
                    System.err.println("Id="+myLinkId+":TRUE:getAccao:isValueReference:"+myLinkAction);
                    MethodBinding vb = getFacesContext().getApplication().createMethodBinding(myLinkAction, null);
                    myLink.setAction(vb);
               } else {
                    System.err.println("Id="+myLinkId+":FALSE:getAccao:isValueReference:"+myLinkAction);
                    final String outcome = cNfo.getAccao();
                    MethodBinding vb = Util.createConstantMethodBinding( myLinkAction );
                    myLink.setAction(vb);
          myLink.encodeBegin(getFacesContext());
          myLink.encodeEnd(getFacesContext());
}This seems to work, but not quite ... the link appears as expected, the value references for value and style are correctly passed, but the action doesn't work at all.
For example if I change to:
String myLinkValue = "#{mybean.linkText}";And I have the following method created on my managed bean:
     public String getLinkText() {
          return "This is myLink Text!";
     }Is successfully calls and retrieves the value from the method. Same happens to the style property.
Now for the action, if I change to:
String myLinkAction = "#{mybean.doMyLinkAction}";And I have the following method created on my managed bean:
     public String doMyLinkAction() {
          return "backup";
     }The result is nothing ... I mean the method is not called at all. The "backup" is properly defined on my "faces-config.xml":
   <navigation-rule>
      <from-view-id>/testPage.jsp</from-view-id>
      <navigation-case>
         <from-outcome>yes</from-outcome>
         <to-view-id>/yes.jsp</to-view-id>
      </navigation-case>
      <navigation-case>
         <from-outcome>no</from-outcome>
         <to-view-id>/no.jsp</to-view-id>
      </navigation-case>
      <navigation-case>
         <from-outcome>backup</from-outcome>
         <to-view-id>/backup.jsp</to-view-id>
      </navigation-case>
   </navigation-rule>If I create the link manually on the web page:
<h:commandLink id="myLinkManual" value="Manually Created Link" style="" action="#{mybean.doMyLinkAction}"/>It does work (the backup.jsp page is shown), so the methods are properly configured, only the action binding does not work.
Wether I use a string "backup" or a reference "#{mybean.doMyLinkAction}" I cannot make it work.
On the console I get the following results, for each value I test (string "backup" or reference "#{mybean.doMyLinkAction}"):
Id=idMyLink:TRUE:getAccao:isValueReference:backup
Id=idMyLink:FALSE:getAccao:isValueReference:#{mybean.doMyLinkAction}So the "if (CommandLinkTag.isValueReference( myLinkAction )) {" is working properly ... that just leaves me with the action method binding instructions ...
Why don't they work?
Any Help Appreciated ... Thanks in Advance!

c'mon guys ... can anyone test this and help me out?
Pleeeeeease ... I'm really needing this working out.
Thanks

Similar Messages

  • Dynamically add some elements in WebService operation request

    Hi, 
    I have a WebService element defined in my mxml which use to make soap calls. 
    I need to dynamically add some repeating groups for action (dependent on action) in the following example. 
    How can I add this in Action Script section? Can I access the WebService  by id userRequest and specify " 
    userRequest.operations.DoAction.request.DoItemActionRequest.action.requiresAdditionItems.n ameValuePair.name = "SomeName"; 
    userRequest.operations.DoAction.request.DoItemActionRequest.action.requiresAdditionItems.n ameValuePair.name = "SomeValue";  
    <mx:WebService  id="userRequest" wsdl="{Application.application.wsdl}" > 
         <mx:operation name="DoAction" resultFormat="object" 
          fault="faultHandler(event)" 
          result="DoActionHandler(evnt)">
            <mx:request> 
              <DoActionRequest> 
                 <userId>{Application.application.userID}</userId> 
                  <action> 
                     <actionId>{selectedItem.actionId}</actionId> 
                 </action> 
              </DoActionRequest> 
             </mx:request> 
           </mx:operation> 
    </mx:WebService>
    Thanks,
    Amitava

    Hi miguel8312,
    Thanks for your suggestion. I understand the steps you explained for defining, calling and processing the result from a webservice from a MXML body.
    My query is specifically, can I modify the webservice request defination from AS function before making the call?
    In my example, if I need to dynamically add a name value pair for <action> tag (e.g. actionParam ), how do I do that?
    Thanks,
    Amitava

  • How can I dynamicly add control elements to a  form

    Hello,
    I want to dynamicly add elements to a JPanel.
    The elements with the properties are stored in a database
    each record contains one element
    Label
    Combobox
    Checkbox
    I`m programming in NetBeans 5.5
    Something like:
    public void test()
    try
    stmt = GeneralDBConnect.createStatement();
    ResultSet rs = stmt.executeQuery("select device_option_id, objecttype, device_option, size, location, tooltip from device_option where ...");
    int i = 0;
    if(rs.next())
    i = i + 1;
    switch(rs.getString(2))
    case "Label" : JLabel Element[i] = new JLabel();
    Element.setText(rs.getString(3));
    break;
    case "Textbox" : JTextField Element[i] = new JTextField();
    break;
    case "Combobox" : JComboBox Element[i] = new JCombobox();
    Element[i].setToolTipText(rs.getString(6));
    ResultSet List = stmt.executeQuery("select device_option_value_id, option_value from device_option_value where ...");
    while(List.next)
    Element[i].addItem(List.getString(2));
    List.close();
    break;
    case "Checkbox" : JCheckBox Element[i] = new JCheckBox();
    break;
    jPanel_Device_Option.add(Element[i])
    rs.close();
    stmt.close();
    catch (SQLException ex)
    ex.printStackTrace();
    I know the Element[i] is wrong code but I need to give the elements an unique name.
    Can anyone assist me in this matter

    Hello everybody,
    I figured it out. I had to change the layout model of the JPanel.
    I`ve chosen to use the gridbaglayout because its very flexibel. See http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html
    Here is my code:
    Description:
    Whenever an item in a Combobox is changed (representing devices) the optional elements (a collection of Textfields, checkboxes, comboboxes) are shown in a JPanel.
    Which Elements are shown is stored in a database. (Tabels device, device_option and device_option_value (stores the JCombobox items))
    First create a JPanel in the graphical editor and right click it choose set layout\gridbaglayout
            jPanel_Device_Option.setLayout(new java.awt.GridBagLayout());
            jPanel_Device_Option.setBorder(javax.swing.BorderFactory.createTitledBorder("Device Options"));
            jPanel_Device_Option.setAutoscrolls(true);Then to create an empty border so the elements don`t clip to the edge of the JPanel add the following code in the properties window in the code section under node "Post-Init code"
            Border bBorder = jPanel_Device_Option.getBorder();
            Border bMargin = new EmptyBorder(0,10,0,10);
            jPanel_Device_Option.setBorder(new CompoundBorder(bBorder, bMargin));Then declare the public variables at the beginning of the code
        public static ArrayList aDatasetElements;
        public static JLabel[] aLabel;
        public static JLabel[] aTextfieldLabel;
        public static JTextField[] aTextfield;
        public static JLabel[] aComboboxLabel;
        public static JComboBox[] aCombobox;
        public static JLabel[] aCheckboxLabel;
        public static JCheckBox[] aCheckbox;And now the method that`s creating the elements
      public void setOutputSettings()
          jPanel_Device_Option.removeAll();//Clear all existing elements from the JPanel
          jPanel_Device_Option.repaint();//Refresh the JPanel
          if(jComboBox_Output.getSelectedItem().toString().length() > 0)//Check if any elements should be added
              GridBagConstraints gbConstraint = new GridBagConstraints();//Create a new gridbagcontraint (properties of layout) check http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html
              gbConstraint.fill = GridBagConstraints.HORIZONTAL;
              gbConstraint.anchor = GridBagConstraints.PAGE_START;
              gbConstraint.weightx = 0.5;
              try
                  stmt = GeneralDBConnect.createStatement();
                  /*Collect data from the database (Which elements should be displayed)  
                      deviceoption: The name of the option this is displayed in the elements label as text
                      tooltip: Show a tooltip on both label and element
                      device_optio_id: gets the ID needed to get the list values for a combobox also easy to use when getting the data afterwards (stored in a public variable
                      objecttype: Label, Textfield, Checkbox, Combobox*/
                  ResultSet rsElements = stmt.executeQuery("select device_option, tooltip, device_option_id, objecttype from device_option where deviceid = (select device_id from device where devicename = \'" + jComboBox_Output.getSelectedItem() + "\') order by sequence_order asc");
                  aDatasetElements = new ArrayList(); // Makes an array
                  while(rsElements.next()) //get data in arraylist (a resultset closes after a while (garbitch collector) resulting in errors I recieved some errors resulset allready closed. Also needed to acces data afterwards
                      aDatasetElements.add(new String(rsElements.getString(1)) + " ;" + new String(rsElements.getString(2)) + ";" + new Integer(rsElements.getInt(3)) + ";" + new String(rsElements.getString(4)));
                  rsElements.close();
                  aLabel = new JLabel[aDatasetElements.size()];          //Makes an array
                  aTextfieldLabel = new JLabel[aDatasetElements.size()]; //Makes an array
                  aTextfield = new JTextField[aDatasetElements.size()];  //Makes an array
                  aCheckboxLabel = new JLabel[aDatasetElements.size()];  //Makes an array
                  aCheckbox = new JCheckBox[aDatasetElements.size()];    //Makes an array
                  aComboboxLabel = new JLabel[aDatasetElements.size()];  //Makes an array
                  aCombobox = new JComboBox[aDatasetElements.size()];    //Makes an array
                  for(int i = 0; i < aDatasetElements.size(); i++) //loop through the foundset
                      String sDatasetElements = aDatasetElements.get(i).toString(); //get the data from the array
                      //Creation of Elements of type Label
                      if(sDatasetElements.split(";")[3].equals("Label")) //Check objecttype
                          gbConstraint.gridx = 0; //X position in layout (Label)
                          gbConstraint.gridy = i; //Y position in layout (Label)
                          aLabel[i] = new JLabel(sDatasetElements.split(";")[0], aLabel.TRAILING); //Makes a JLabel at an array place
    aLabel[i].setToolTipText(sDatasetElements.split(";")[1]);
    jPanel_Device_Option.add(aLabel[i], gbConstraint); //Adds a JLabel to the JPanel
    //Creation of Elements of type TextField
    if(sDatasetElements.split(";")[3].equals("Textfield"))
    gbConstraint.gridx = 0; //X position in layout (Label)
    gbConstraint.gridy = i; //Y position in layout (Label)
    aTextfieldLabel[i] = new JLabel(sDatasetElements.split(";")[0], aTextfieldLabel[i].TRAILING); //Makes a JTextfield at an array place
    aTextfieldLabel[i].setToolTipText(sDatasetElements.split(";")[1]);
    jPanel_Device_Option.add(aTextfieldLabel[i], gbConstraint); //Adds a JLabel to the JPanel
    gbConstraint.gridx = 1; //X position in layout (Element)
    gbConstraint.gridy = i; //Y position in layout (Element)
    aTextfield[i] = new JTextField(); //Makes a JTextfield at an array place
    aTextfield[i].setToolTipText(sDatasetElements.split(";")[1]);
    jPanel_Device_Option.add(aTextfield[i], gbConstraint); //Adds a JTextField to the JPanel
    //Creation of Elements of type Checkbox
    if(sDatasetElements.split(";")[3].equals("Checkbox"))
    gbConstraint.gridx = 0; //X position in layout (Label)
    gbConstraint.gridy = i; //Y position in layout (Label)
    aCheckboxLabel[i] = new JLabel(sDatasetElements.split(";")[0], aCheckboxLabel[i].TRAILING); //Makes a JLabel at an array place
    aCheckboxLabel[i].setToolTipText(sDatasetElements.split(";")[1]);
    jPanel_Device_Option.add(aCheckboxLabel[i], gbConstraint); //Adds a JLabel to the JPanel
    gbConstraint.gridx = 1; //X position in layout (Element)
    gbConstraint.gridy = i; //Y position in layout (Element)
    aCheckbox[i] = new JCheckBox(); //Makes a JCheckbox at an array place
    aCheckbox[i].setToolTipText(sDatasetElements.split(";")[1]);
    jPanel_Device_Option.add(aCheckbox[i], gbConstraint); //Adds a JCheckbox to the JPanel
    //Creation of Elements of type Combobox
    if(sDatasetElements.split(";")[3].equals("Combobox"))
    gbConstraint.gridx = 0; //X position in layout (Label)
    gbConstraint.gridy = i; //Y position in layout (Label)
    aComboboxLabel[i] = new JLabel(sDatasetElements.split(";")[0], aComboboxLabel[i].TRAILING); // Makes a JLabel at an array place
    aComboboxLabel[i].setToolTipText(sDatasetElements.split(";")[1]);
    jPanel_Device_Option.add(aComboboxLabel[i], gbConstraint); //Adds a JLabel to the JPanel
    gbConstraint.gridx = 1; //X position in layout (Element)
    gbConstraint.gridy = i; //Y position in layout (Element)
    aCombobox[i] = new JComboBox(); //Makes a JCombobox at an array place
    aCombobox[i].setToolTipText(sDatasetElements.split(";")[1]);
    jPanel_Device_Option.add(aCombobox[i], gbConstraint); //Adds a JCombobox to the JPanel
    //Get the listvalues from the database option_value is the value that is shown in the list
    ResultSet rsValuelist = stmt.executeQuery("select option_value from device_option_value where device_optionid = " + sDatasetElements.split(";")[2] + " and (option_state = " + iOptionState + " or option_state = 40) order by sequence_order");
    while(rsValuelist.next())
    if(rsValuelist.getString(1) == null)
    aCombobox[i].addItem("");
    else
    aCombobox[i].addItem(rsValuelist.getString(1));
    rsValuelist.close();
    //Place an empty label at the bottom otherwice the labels are centered in the JPanel
    gbConstraint.anchor = GridBagConstraints.PAGE_END;
    gbConstraint.weighty = 1.0;
    gbConstraint.gridx = 0;
    gbConstraint.gridy = aDatasetElements.size() + 1;
    jPanel_Device_Option.add(new JLabel(""), gbConstraint); //Adds an empty JLabel to the JPanel
    catch (SQLException ex)
    ex.printStackTrace();
    The is triggered in the init method and the event Item changed of the JCombobox
    private void jComboBox_Output_ItemStateChanged(java.awt.event.ItemEvent evt) {                                                  
          //Removed some irrelevant code here
          setOutputSettings();
        }To collect the data that the user has entered in the elements
    private void jButton_Collect_User_Data_ActionPerformed(java.awt.event.ActionEvent evt) {                                              
          String sList = "";
          for(int i = 0; i < aDatasetElements.size(); i++)
              String sDatasetElements = aDatasetElements.get(i).toString();
              if(sDatasetElements.split(";")[3].equals("Label"))
                  sList = sList + aLabel.getText() + "\n";
    if(sDatasetElements.split(";")[3].equals("Textfield"))
    sList = sList + aTextfield[i].getText() + "\n";
    if(sDatasetElements.split(";")[3].equals("Checkbox"))
    sList = sList + aCheckbox[i].isSelected() + "\n";
    if(sDatasetElements.split(";")[3].equals("Combobox"))
    sList = sList + aCombobox[i].getSelectedItem().toString() + "\n";
    JOptionPane.showMessageDialog(null, sList);
    I hope ths is helpfull information.
    Since I`m totally new to Java it is possible that a different approach is better however this is working for me.
    I`m open for any remarks on the code and feel free to give any comments.
    Kind Regards Rene

  • How to populate data dynamically in WSelect web element.

    How to populate data dynamically in WSelect web element. what is the syntax of WSelect web element to populate data from the database

    Hi Jamie,
    There is no Url to download ackage, instead the link is taking here
    Crystal Reports webElements
    Can you give me correct link?

  • How do you add a link to a .swf file?

    Is there a way to add a link/URL to a .swf file, without embedding into the original .fla file?
    Is there any way to do that with just the .swf file alone, and without actually editing the .fla or re-creating it?

    I won't be providing lessons, but here's the basics...  to load the other swf file using AS3 you will use code like the following in the main timeline...
    var my_loader:Loader = new Loader();
    my_loader.load(new URLRequest("theOther.swf"));
    addChild(my_loader);
    addChild(myBtn); // described next but coded here
    To add a link, you can create an invisible button and place whereever you like in the timeline, or if its a text link you can assign the link to the dynamic textfield via the properties panel.  To create an invisible button just create a button symbol and draw a shape for it only in its Hit frame, leaving all other empty... that way you can still see the button to work with it on the stage, but it will be invisible when the file plays.  You could also have the button include text or any other visual you desire if you don't need/want it to be invisible.
    If you use the button approach, then you need to assign the button an instance name (I use "myBtn" for this example)  Then you have to assign an event listener and event handler function for the button...
    myBtn.addEventListener(MouseEvent.CLICK, clickBtn);
    function clickBtn(evt:MouseEvent):void {
         navigateToURL(new URLRequest("http://www.yourlinksurl.com/etc"));
    The reason I addChild for myBtn after I addChild the Loader is so that it will sit above the Loader.  Without that line, the Loader would have the loaded swf sitting atop the button blocking access to it.
    If you plan to use a Textfield instead of a button, then you don't need the event code but you still need the addChild() line to bring it in front.  As mentioned already you can link it via the properties panel field for a link.  To make life simple per these instructions just assign the textfield an instance name of myBtn.

  • When I add a link to an image it stops aligning with text

    I have my icon vertically aligned perfectly with a line of text right after it, but when I add a link to the icon, the text moves to the top of the image (not above it, but just aligned to the top of the image so it isn't centered vertically anymore). I am not changing anything but adding the link. I have had this issue before and wasn't able to fix it....

    If you created your page from a Dreamweaver template, I am not surprised that it set images up to display: block; Here is what that does:
    The element is displayed as a block element (like paragraphs and headers). A block element has some whitespace above and below it and does not tolerate any HTML elements next to it
    You could also (if you want to have whitespace above and below image elements) try display: inline-block; Here is what that does:
    The element is placed as an inline element (on the same line as adjacent content), but it behaves as a block element
    Remember: display: inline; is the default.

  • How to add a link under quick launch using custom actions?

    http://msdn.microsoft.com/en-us/library/office/bb802730(v=office.15).aspx
    Custom actions allow us to create feature to add a link under site settings, site actions menu and even central admin.
     Is there any way we can extend this feature to allow links being added under quick launch? I tried providing location Microsft.SharePoint.Navigation but that had no effect

    hi
    you don't need to use custom actions in order to add links to the quick launch menu. It allows to add links programmatically to the menu items collections directly, see e.g.
    Adding Links to Quick Launch. From this link check the following example which adds an item under the Lists heading in Quick Launch.:
    using System;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Navigation;
    namespace ConsoleApp
    class Program
    static void Main(string[] args)
    using (SPSite site = new SPSite("http://localhost"))
    using (SPWeb web = site.OpenWeb())
    // Get the Links list or create it if it does not exist.
    SPList list = web.Lists.TryGetList("Links");
    if (list == null || list.BaseTemplate != SPListTemplateType.Links)
    // Create the list.
    Guid listId = web.Lists.Add("Links", "Interesting hyperlinks", SPListTemplateType.Links);
    list = web.Lists.GetList(listId, false);
    // Check for an existing link to the list.
    SPNavigationNode listNode = web.Navigation.GetNodeByUrl(list.DefaultViewUrl);
    // No link, so create one.
    if (listNode == null)
    // Create the node.
    listNode = new SPNavigationNode(list.Title, list.DefaultViewUrl);
    // Add it to Quick Launch.
    listNode = web.Navigation.AddToQuickLaunch(listNode, SPQuickLaunchHeading.Lists);
    Console.Write("\nPress ENTER to continue....");
    Console.ReadLine();
    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

  • Need to add new UI elements in HAP_PMP_OVERALL_APPRAISAL view VW_MAIN

    Hi,
    how to add new UI elements (input field, read only field and button) on VW_MAIN view of HAP_PMP_OVERALL_APPRAISAL .
    This is about ESS MSS Performance Mgmt.
    I am checking for enhancement modifications, enhacement spots, dynamic programming to add new UI elements etc.
    kindly provide inputs
    thanks
    B

    Hi,
    The following procedure explains how to add UI elements in the view of the standard component.
    1. Create an Enhancement Implementation.
    2. Create a new node on Component controller context.
    3. Create a new method on component controller as the supply function of the new node.
    4. Create new node on the view context by binding it from the controller context.
    5. Create the UI elements on view.
    6. Create post-exit on view method DoModifyView.--> In order to handle the events of UI element newly added.
    7. Create a pre-exit on component method(Ex: SAVEAPPRAISALDATA) --> to get the static attributes of node.
    Hope, the above steps will be useful .
    Regards,
    Abi

  • Is there a way to add a link to Light Box?

    I just want to know if there is a way to add a link to Light box? , so when you click the image light box opens and you see a link displayed under the image. Where would I add the link, between what tags?
    [HTML] Lightbox Link - Pastebin.com

    The original markup is
    <a href="assets/images/Alogo.png" data-lightbox="Illustratorwork" data-title="Angie - A client who wanted a logo created for her own personal use."><img src="assets/images/Alogo.png" alt=" A client who wanted a logo created"></a>
    When jQuery has finished with it, the markup becomes
    <div style="display: block; width: 1779px; height: 817px;" id="lightboxOverlay" class="lightboxOverlay"></div><div style="display: block; top: 50px; left: 0px;" id="lightbox" class="lightbox"><div style="width: 811px; height: 608px;" class="lb-outerContainer"><div class="lb-container"><img style="display: block; width: 803px; height: 600px;" class="lb-image" src="assets/images/Alogo.png"><div style="display: block;" class="lb-nav"><a style="display: none;" class="lb-prev" href=""></a><a style="display: block;" class="lb-next" href=""></a></div><div style="display: none;" class="lb-loader"><a class="lb-cancel"></a></div></div></div><div style="display: block; width: 811px;" class="lb-dataContainer"><div class="lb-data"><div class="lb-details"><span style="display: block;" class="lb-caption">Angie - A client who wanted a logo created for her own personal use.</span><span class="lb-number">Image 1 of 4</span></div><div class="lb-closeContainer"><a class="lb-close"></a></div></div></div></div>
    You will notice that the original is wrapped in an anchor element, stopping us from placing an anchor element around the title. Yet in the finished markup, the caption does not reside within an anchor element. To wrap the caption in an anchor element we have to fool the browser by using character entities for less than (<) , greater than (>) and quote (') signs. Once the page/modal is displayed, the browser will interpret the entities to what we want.

  • Add new link on Quick Launch using visual studio

    Hi,
    How can I add new link on quick launch using visual studio?
    I saw many link about developing quick launch or top link bar.
    But they are using visual webpart to develop this function and can add
    when the user add this webpart. How can I add automatically when I deploy the project.
    Thanks in advance!
    Best Regards, wendy

    using System;
    using System.Web.UI;
    using System.Linq;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Navigation;
    namespace SPQuickLaunchAddItemWebPart.VisualWebPart1
    public partial class VisualWebPart1UserControl : UserControl
    protected void Page_Load(object sender, EventArgs e)
    CleanUpQuickLaunch(“My Header”);
    AddQuickLaunchItem(“My Header”, “http://www.google.com/q=stuff”, “My Link Here”, “http://www.google.com”);
    CleanUpTopNavigationBar(“My Header”);
    AddTopNavigationBarItem(“My Header”, “http://www.google.com/q=stuff”, “My Link Here”, “http://www.google.com”);
    AddTopNavigationBarItem(“My Header”, “http://www.google.com/q=stuff”, “My Link Here1″, “http://www.google.com”);
    public static void CleanUpQuickLaunch(string header)
    using (SPSite site = SPContext.Current.Site)
    using (SPWeb web = site.OpenWeb())
    web.AllowUnsafeUpdates = true;
    SPNavigationNodeCollection quickLaunch = web.Navigation.QuickLaunch;
    // try to get quick launch header
    SPNavigationNode nodeHeader = quickLaunch.Cast<SPNavigationNode>().Where(n => n.Title == header).FirstOrDefault();
    //if header not found remove it
    if (nodeHeader != null)
    quickLaunch.Delete(nodeHeader);
    public static void CleanUpTopNavigationBar(string header)
    using (SPSite site = SPContext.Current.Site)
    using (SPWeb web = site.OpenWeb())
    web.AllowUnsafeUpdates = true;
    SPNavigationNodeCollection topNavigation = web.Navigation.TopNavigationBar;
    // try to get quick launch header
    SPNavigationNode nodeHeader = topNavigation.Cast<SPNavigationNode>().Where(n => n.Title == header).FirstOrDefault();
    //if header not found remove it
    if (nodeHeader != null)
    topNavigation.Delete(nodeHeader);
    public static void AddQuickLaunchItem(string header, string headerURL, string item, string url)
    using (SPSite site = SPContext.Current.Site)
    using (SPWeb web = site.OpenWeb())
    web.AllowUnsafeUpdates = true;
    SPNavigationNodeCollection quickLaunch = web.Navigation.QuickLaunch;
    // try to get quick launch header
    SPNavigationNode nodeHeader = quickLaunch.Cast<SPNavigationNode>().Where(n => n.Title == header).FirstOrDefault();
    //if header not found create it
    if (nodeHeader == null)
    nodeHeader = quickLaunch.AddAsFirst(new SPNavigationNode(header, headerURL, true));
    nodeHeader.Update();
    //try to get node item under header
    SPNavigationNode nodeItem = nodeHeader.Children.Cast<SPNavigationNode>().Where(n => n.Title == item).FirstOrDefault();
    //If item not found under heading then create it
    if (nodeItem == null)
    nodeItem = nodeHeader.Children.AddAsLast(new SPNavigationNode(item, url, true));
    else
    nodeItem.Url = url;
    nodeItem.Update();
    nodeHeader.Update();
    public static void AddTopNavigationBarItem(string header, string headerURL, string item, string url)
    using (SPSite site = SPContext.Current.Site)
    using (SPWeb web = site.OpenWeb())
    web.AllowUnsafeUpdates = true;
    SPNavigationNodeCollection topNavBar = web.Navigation.TopNavigationBar;
    // try to get quick launch header
    SPNavigationNode nodeHeader = topNavBar.Cast<SPNavigationNode>().Where(n => n.Title == header).FirstOrDefault();
    //if header not found create it
    if (nodeHeader == null)
    nodeHeader = topNavBar.AddAsFirst(new SPNavigationNode(header, headerURL, true));
    nodeHeader.Update();
    //try to get node item under header
    SPNavigationNode nodeItem = nodeHeader.Children.Cast<SPNavigationNode>().Where(n => n.Title == item).FirstOrDefault();
    //If item not found under heading then create it
    if (nodeItem == null)
    nodeItem = nodeHeader.Children.AddAsLast(new SPNavigationNode(item, url, true));
    else
    nodeItem.Url = url;
    nodeItem.Update();
    nodeHeader.Update();
    above code demonstrate how to add node inside the quick launch and top navigation.
    you can also follow the below link.
    http://myspexp.com/2012/04/30/adding-items-to-your-quick-launch-or-top-navigation-programmatically/
    Hiren Patel | Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.

  • Dynamically add web part in sandbox solution

    I've site in office 365. I want to add site page in /SitePages on feature activation. I also want to dynamically add web part in this site page.
    How can I do this?

    Hi,
    According to your description, you might want to add a page into the “Site Pages” library and add a web part into it in the FeatureActivated event in a Sandboxed solution.
    To add a site page, you can refer to the two links below:
    http://www.c-sharpcorner.com/blogs/4526/programmatically-create-wiki-page-in-sharepoint.aspx
    http://sharepoint2010mind.blogspot.ch/2012/06/add-publishing-page-to-sharepoint-site.html
    Then add a web part to the page:
    http://blog.mastykarz.nl/inconvenient-provisioning-web-parts-wiki-pages-sandboxed-solutions/
    Best regards
    Patrick Liang
    TechNet Community Support

  • Need to Add Help links to ESS pages

    Hello,
    I have a requirement to add helps links to ESS services like address etc.
    The services have the roadmap element. Is it possible to add the link besides the roadmap element and right aligned?
    Which component should the link be added to?
    Is it possible that all the personal info services will have the link pointing to respective URLs?
    I figured that I might have to change the sap.compcui_gpxssutils DC. Am I right?
    But here I face a problem, that the DC is not modifiable in the DTR.
    Please let me know your suggestions.
    Thanks and regards,
    Mayuresh

    Hi,
    In Homepage Framework for ESS, there is a help service with every service. Check if this will help you.
    You can create a service as a help service. EIC_SERVICE_REQUEST is an example of help service provided by SAP. Then you can configure this help service to any service you want. This way you can provide access to help informationm without changing the code.
    To create your own help service, you can upload the help documents(say HTML) in portal KM repository. Create a KM document iView for the document. Create a page out of the iView and configure the PCD path of the page in the Hompageframework service.
    Regards
    Srini

  • ADD A LINK AROUND MAIN IMAGE IN PHOTO GALLERY

    Can anyone help with the code for this. I need to add a link
    to each image as it appear in the spry photo gallery. Each link
    would be different and set in the xml file can some one help
    please. I can't figure this one out.

    It's usually something like:
    <div spry:region="ds1" spry:repeat="ds1">
    <a href="{link_dataref}"><img src="{image_dataref}"
    /></a>
    </div>

  • I designed my social media buttons. How do I add the link to each one. For example: How do I add my Facebook link to my face book button on my muse site?

    I designed my social media buttons. How do I add the link to each one. For example: How do I add my Facebook link to my facebook button on my muse site?

    Hello,
    Please select the button that you have created and go to hyperlink tab and add the facebook page URL there.
    Please take a look at the screenshot below.
    Regards
    Vivek

  • How to add new links to a page

    Hello Community
    In Sharepoint 2013 Server can you create:
    A Link in the left navigtion bar  or Quick Launch
     when clicked it can open a new page  and on that page there is an “Add New” type of 
    button. 
    Then on that page you can add as many links as the page will allow, each 
    of those links can contain a url
        Thank you
        Shabeaut

    Hi,
    To add a new link on the left nav:
    You can go to site settings> navigation> add a link under "current navigation".
    For the second requirement:
    You can create a "links" list and add it to that second page. This way you can have that "Add Links" option and add links.
    Thanks,
    norasampang

Maybe you are looking for

  • How do I use my I'd for the app store and not my wife.

    IT always ask for my wife password and I need it to ask for my password. So I need to change it so it will show my ID and not hers.

  • Passing drop down values to email in Lifecycle 8

    Hello, I have a form which i have been playing with but havent got it quite working how i would like. I have an access database with dealer name, dealer code, and fmt email. What I have the form doing is displaying the dealer name in a drop down box

  • Trouble with ZEN MX

    Trouble with ZEN MXWHi, I have some issues with my zen mx,? primarily sometimes when I listen to a playlist containing many tracks or "all tracks", my player sometimes shuts of and then have to scan the disk pefore working. Secondly there are small p

  • Does anyone know how to delete a template created in error using PAGES?

    I created some templates in error using PAGES and cannot figure out how to remove them/delete them.  Anyone know how to do this?  Fran

  • Error in Annual points Logic????

    Hi seems that the Logic for annual points calulation is in error. as it is taking 1 month difference from current date instead of 1 year difference. Regards Rajendra